package com.ckf.serene.controller;

import com.ckf.serene.domain.VipOrderParam;
import com.ckf.serene.domain.WXPayParam;
import com.ckf.serene.domain.WeChatTransferParam;
import com.ckf.serene.domain.WxRefundParam;
import com.ckf.serene.service.WeChatPayService;
import com.ckf.serene.utils.AjaxResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * 微信api
 * <p>
 * 传参规范按照官方文档
 *
 * @author serence
 * @date 2021/11/6 23:39
 */
@Slf4j
@RestController
@RequestMapping("/weChatPay/")
public class WeChatController {

    @Autowired
    private WeChatPayService weChatPayService;


    /**
     * 小程序支付V3
     *
     * @param param 支付参数类
     * @return
     */
    @PostMapping("appletsV3")
    public AjaxResult appletsV3(@Validated @RequestBody WXPayParam param) {
        return AjaxResult.success(weChatPayService.appletsV3(param));
    }


    /**
     * 微信app支付 V3版本
     *
     * @param param 微信支付传参类
     * @return
     */
    @PostMapping("weChatAppPayV3")
    public AjaxResult weChatAppPayV3(@Validated @RequestBody VipOrderParam param) {
        return AjaxResult.success(weChatPayService.weChatAppPayV3(param));
    }

    /**
     * 微信退款
     *
     * @param wxRefundParam 微信退款参数类
     * @return 微信退款
     */
    @PostMapping("weChatRefund")
    public AjaxResult weChatRefund(@RequestBody WxRefundParam wxRefundParam) {
        return AjaxResult.success(weChatPayService.weChatRefund(wxRefundParam));
    }


    /**
     * 微信支付成功回调通知
     *
     * @param request 回调信息
     * @return
     */
    @RequestMapping("weChatPaySuccess")
    public AjaxResult weChatPaySuccess(HttpServletRequest request) {
        return AjaxResult.success(weChatPayService.weChatPaySuccess(request));
    }


    /**
     * 微信退款成功回调通知
     *
     * @param request 回调信息
     * @return
     */
    @RequestMapping("weChatRefundCallback")
    public AjaxResult weChatRefundCallback(HttpServletRequest request) {
        return AjaxResult.success(weChatPayService.weChatRefundCallback(request));
    }


    /**
     * 企业转账到零钱  微信
     *
     * @param chatTransferParam 微信转账参数类
     * @return
     */
    @RequestMapping("weChatPaymentToChange")
    public AjaxResult weChatPaymentToChange(WeChatTransferParam chatTransferParam) {
        return AjaxResult.success(weChatPayService.weChatPaymentToChange(chatTransferParam));
    }


}
